package IC.Symbols;

import IC.AST.ASTNode;
import IC.Types.Type;

public class Symbol {
	private ASTNode astNode;
    private int symbolDistance;
	private int level = 0;
	private Object symbolSemantic = null;
	private String symbolName;
	private Kind symbolKind;
	private Type symbolType;
	private String lirTitle;



	public Symbol(String name, Type type, Kind kind) {
		symbolName = name;
		symbolKind = kind;
		symbolType = type;
	}
	
	public Symbol(String name, Type type, Kind kind, ASTNode astNode) {
		symbolName = name;
		symbolKind = kind;
		symbolType = type;
		this.astNode = astNode;
	}


	public String toString() {
		String innerInfo = "";
		String[] infoArray = new String[2];
		
		PopulateInfoArray(infoArray);

		if (symbolKind.PrintNameFirst())
			innerInfo = String.format("%s %s", infoArray[1],infoArray[0]).trim();
		else
			innerInfo = String.format("%s %s", infoArray[0],infoArray[1]).trim();

		return (innerInfo.length() == 0) ? symbolKind.toString() : String
				.format("%s: %s", symbolKind.toString(), innerInfo.trim());
	}

	private void PopulateInfoArray(String[] infoArray) {
		if (symbolKind.PrintableTypeName())
			infoArray[0] = symbolType.getTypeName();
		if (symbolKind.PrintableSymbolName())
			infoArray[1] = symbolName;
	}

	public int getLevel() {
		return level;
	}

	public void setSemantic(Object semantic) {
		symbolSemantic = semantic;
	}

	public void setSymbolLevel(int newLevel) { 
		level = newLevel;
	}

	public Object getSemantic() {
		return symbolSemantic;
	}
	
	public String getName() {
		return symbolName;
	}

	public Kind getKind() {
		return symbolKind;
	}

	public Type getType() {
		return symbolType;
	}

    public String getLirTitle() {
        return lirTitle;
    }

    public ASTNode getAstNode() {
        return astNode;
    }

    public void setLirTitle(String lirTitle) {
        this.lirTitle = lirTitle;
    }
    
    public void setAstNode(ASTNode astNode){
    	this.astNode = astNode;
    }

	public int getSymbolDistance() {
		return symbolDistance;
	}

	public void setSymbolDistance(int distance) {
		symbolDistance = distance;
	}


}
